package cn.victory.pattern1;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import org.junit.Test;


/**
 * @ Description LettuceDemo
 * @ Author victory
 * @ Date 2022/6/7
 **/
public class Lettuce {
    @Test
    public void testLettuce(){
        //创建URI客户端参数
        RedisURI redisUri = RedisURI.create("redis://localhost/");
        //创建客户端
        RedisClient redisClient = RedisClient.create(redisUri);
        //创建连接
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        //创建同步命令
        RedisCommands<String, String> commands = connection.sync();
        //设置值
        commands.set("user", "victory");
        //获取值
        String user = commands.get("user");
        System.out.println(user);
        //关闭连接
        connection.close();
        //关闭客户端
        redisClient.shutdown();
    }
}
